# 作者: YYJ
# 2025年06月12日16时32分15秒
# 2486249622@qq.com

from collections import deque


class Deque:
    def __init__(self):
        self.deque = deque()

    def add_front(self, ele):
        self.deque.appendleft(ele)

    def add_rear(self, ele):
        self.deque.append(ele)

    def remove_front(self):
        return self.deque.popleft() if self.deque else None

    def remove_rear(self):
        return self.deque.pop() if self.deque else None

    def front(self):
        if self.empty():
            return "deque is empty"
        return self.deque[0]

    def rear(self):
        if self.empty():
            return "deque is empty"
        return self.deque[-1]

    def empty(self):
        return len(self.deque) == 0

    def size(self):
        return len(self.deque)


if __name__ == '__main__':
    dq = Deque()
    dq.add_rear(1)
    dq.add_rear(2)
    dq.add_front(3)
    print(dq.deque)  # 输出: deque([3, 1, 2])

    dq.remove_front()
    dq.remove_rear()
    print(dq.deque)  # 输出: deque([1])
